﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Library;

namespace Sport_Shop.Winform
{
    public partial class QLHoaDon : Form
    {
        public QLHoaDon()
        {
            InitializeComponent();
        }

        List<HoaDonNhap> ListHDN = new List<HoaDonNhap>();

        //Button Nhập hàng
        #region Button Nhập hàng
        private void btNhaphang_Click(object sender, EventArgs e)
        {
            QLHoaDonNhap qlhdn = new QLHoaDonNhap();
            DialogResult dr = qlhdn.ShowDialog();
            if (dr == DialogResult.OK)
            {
                ListHDN = HoaDonNhap.GetList();
                dgvHDNhap.DataSource = null;
                dgvHDNhap.DataSource = ListHDN;
            }
        }
        #endregion

        //Form Load
        #region Form Load
        private void QLHoaDon_Load(object sender, EventArgs e)
        {
            //Load gridview
            ListHDN = HoaDonNhap.GetList();

            dgvHDNhap.AutoGenerateColumns = false;
            dgvHDNhap.DataSource = ListHDN;
        }
        #endregion

        //Lọc theo ngày
        #region Lọc theo ngày
        private void dateTu_ValueChanged(object sender, EventArgs e)
        {
            List<HoaDonNhap> result = null;

            result = HoaDonNhap.FilterList(dateTu.Value, dateDen.Value, ListHDN);

            dgvHDNhap.AutoGenerateColumns = false;
            dgvHDNhap.DataSource = null;
            dgvHDNhap.DataSource = result;
        }
        #endregion

        //Load Chi Tiết HDN
        #region Load Chi Tiết HDN
        private void dgvHDNhap_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                HoaDonNhap hdn = (HoaDonNhap)dgvHDNhap.Rows[e.RowIndex].DataBoundItem;

                List<ChiTietHDN> ListChiTietHDN = new List<ChiTietHDN>();

                ListChiTietHDN = ChiTietHDN.GetList(hdn.MaHDN);

                dgvCTHDNhap.AutoGenerateColumns = false;
                dgvCTHDNhap.DataSource = null;
                dgvCTHDNhap.DataSource = ListChiTietHDN;
            }
        }
        #endregion
    }
}
